package org.example.client.veri.bind;

import java.lang.reflect.Proxy;

/**
 * @author mojito
 * @Classname ServiceProxyFactory
 * @Description TODO
 * @Date 2020/7/20 下午10:05
 **/
public class ServiceProxyFactory<T> {
    private Class<T> face;

    public ServiceProxyFactory(Class<T> face) {
        this.face = face;
    }

    protected T newInstance(ServiceProxy<T> proxy) {
        return (T) Proxy.newProxyInstance(face.getClassLoader(), new Class[]{face}, proxy);
    }

    public T newInstance(Client client) {
        final ServiceProxy<T> proxy = new ServiceProxy<>(face, client);
        return newInstance(proxy);
    }
}
